<template>
  <div class="list-content">
    <div class="list-header clearfix">
      <div class="list-header-tit fl">依申请查询</div>
       <div class="list-close fr" style="font-size: 16px;background:#ffffff;">
        <span @click="backHome">返回首页：</span>
        <img src="../../assets/image/backhome.png" style="width:24px;height:24px;" @click="backHome">
        <span @click="outmything">&nbsp;&nbsp;依申请公开&nbsp;&nbsp;</span>
                <img src="../../assets/image/jump_to.png" style="width:22px;height:22px;" @click="outmything">
        <!--
        <i @click="backHome" class="list-close el-icon-circle-close"></i>
        -->
      </div>
    </div>
    <div class="list-table">
      <div class="home-table">
        <table class="app-table">
          <thead>
            <th>办事名称</th>
            <th>提交时间</th>
            <th>受理状态</th>
            <th>操作</th>
          </thead>
          <tbody v-if="list.length">
            <tr v-for="item in list" :key="item.id">
              <td style="width:70%" >{{ item.govInfo | filterWords(30)}}</td>
              <td>{{ item.applyTime | formatDate}}</td>
              <td>{{ item.handleStatus | statusHandler }}</td>
              <td><div class="can-btn"  style="cursor:pointer;"  @click="enterMailDetail(item)">详情</div></td>
            </tr>
          </tbody>
          <tbody v-if="!list.length">
            <tr>
              <td>暂无数据</td>
              <td>暂无数据</td>
              <td>暂无数据</td>
              <td>暂无数据</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
    <div class="page-wrap">
      <el-pagination
        background
        :current-page="pageIndex"
        :page-size="pageSize"
        @current-change="pageChange"
        layout="prev, pager, next,jumper"
        :total="Number(total)"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getMailList, getUserInfo } from '@/api'
export default {
  data() {
    return {
      list:[],
      pageIndex:1,
      pageSize:10,
      total:0,
      statusList:[
        { name:'待处理',id:1,},
        { name:'处理中',id:2},
        { name:'已处理',id:3},
        { name:'已废止',id:4}
      ],
    };
  },
  computed:{
    getUser(){
      return this.$store.state.user;
    }
  },
  mounted(){
    this.getData();
  },
  methods:{
    backHome(){
      this.$router.push({ name:'home' });
    },
    pageChange(num){
      this.pageIndex = num;
      this.getList();
    },

    outmything(){
               
      let url = 'http://www.sc.gov.cn/10954/11061/2009/8/5/10154336.shtml';
       window.open(url,"_blank")
    },

    getData(){ // 保证有userid
      if(this.getUser.id){
        this.getList();
      }else{
        let url = '/sys/sysMember/getMember';
        getUserInfo(url).then(res=>{
          if(res.data.code == 200){
            this.$store.commit('setUserinfo',{
              id:res.data.data.id,
              name: res.data.data.realName,
              mobile:res.data.data.mobile,
              userType:res.data.data.userType
            })
            this.getList();
          }
        })
      }
    },
    getList(){
      let url = '/sys/sysMember/personSearchList';
      let params = {
        userType: this.getUser.userType,
        pageNum: this.pageIndex,
        pageSize: this.pageSize,
      }

      let userTy = this.getUser.userType;
      if(userTy=='user'){
        let truname = this.getUser.name;
        let mobilestr  = this.getUser.mobile;
        params.trueName = '*'+ truname.substring(1,truname.length);
        params.phoneNumber = mobilestr.substr(0,3) + '****'+ mobilestr.substr(7,4);
      }
      getMailList(url,params).then(res=>{
        if(res.data.Status == 'true'){
          this.list = res.data.data || [];
          this.total = res.data.pager.totalCount || 0;
        }else{
          this.list = [];
          this.total =0;
        }
      })

    },
    enterMailDetail(item){
      if(process.env.NODE_ENV === "production"){
        window.open("/usercenter/inspectionDetail?id=" + item.id, "_blank")
      }else {
        window.open("/inspectionDetail?id=" + item.id, "_blank")
      }

    }
  },
  filters: {
    statusHandler: function (str) {
      if (!str) {
        return "--";
      } else{
        switch(str)
          {
          case 1:
            str = "待处理";
            break;
          case 2:
            str = "处理中";
            break;
          case 3:
            str = "已处理";
            break;
          default:
            str = "已废止";
          }
      }
      return str; 
    }
  }
};
</script>

<style lang="scss" scoped>

</style>
